package com.yan.controller;

import com.yan.pojo.Student;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.UUID;


@Controller
@RequestMapping("/t")
public class ThymeleafController {
    //入门案例
    @RequestMapping("/h")
    public String sayHello(Model model){
        model.addAttribute("msg","hello,welcome to China!");
        return "hello";
    }
//跳转文本表达式页面
    @RequestMapping("/el")
    public String varEL(Model model, HttpSession session){
        model.addAttribute("result",100+200);
        Student student = new Student();
        student.setName("言言");
        student.setAddress("郑州");
        model.addAttribute("student",student);
        Student student1 = new Student();
        student1.setName("拉拉");
        student1.setAddress("中国");
        session.setAttribute("student1",student1);
        return "t_EL";
    }
    //跳转链接表达式页面
    @RequestMapping("/urlEL")
    public String varEL(){
        return "url_el";
    }
    //跳转首页
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    //跳转字面值页面
    @RequestMapping("/literal")
    public String literal(Model model){
        Student student = new Student();
        student.setName(UUID.randomUUID().toString());
        model.addAttribute("student",student);
        return "literal";
    }
    //跳转数字表达式页面
    @RequestMapping("/calculate")
    public String calculate(int param01, int param02, Model model){
        model.addAttribute("a",param01);
        model.addAttribute("b",param02);
        model.addAttribute("c",2);
        Student student = new Student();
//        student.setSid(UUID.randomUUID().toString());
        model.addAttribute("student",student);
        return "calculate";
    }
    //跳转对象页面
    @RequestMapping("/objTest")
    public String objTest(Model model, HttpServletRequest request, HttpSession session,
                          @CookieValue("JSESSIONID") String jsessionid){
        Student student = new Student();
        student.setName(UUID.randomUUID().toString());
        student.setBirthday(new Date().toString());
        student.setName("rose");
        model.addAttribute("student",student);
        request.setAttribute("requestTest",18);
        session.setAttribute("id",jsessionid);

        return "objTest";
    }
}

